import request from "@/utils/request";

const baseUrl = "studentsBase/";

/**
 * 获取所有学生信息
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
export function page(pagination, keyword) {
    return new request({
        url: `${baseUrl}list`,
        method: "GET",
        params: {...pagination, ...keyword}
    })
}

/**
 * 添加单个学生
 * @returns {AxiosInstance}
 * @param data
 */
export function addStudentBase(data) {
    return new request({
        url: `${baseUrl}`,
        method: "POST",
        data: data
    })
}

/**
 * 修改单个学生
 * @returns {AxiosInstance}
 * @param data
 */
export function updateStudentBase(data) {
    return new request({
        url: `${baseUrl}`,
        method: "PUT",
        data: data
    })
}

/**
 * 删除单个学生
 * @returns {AxiosInstance}
 * @param id
 */
export function deleteStudentBase(id) {
    return new request({
        url: `${baseUrl}?id=${id}`,
        method: "DELETE",
    })
}

/**
 * 删除多个学生
 * @returns {AxiosInstance}
 * @param ids
 */
export function deleteMultipleStudentBase(ids) {
    let filterIds = "?";
    ids.forEach(item => filterIds += `ids=${item}&`);
    filterIds = filterIds.substr(0, filterIds.length - 1);
    return new request({
        url: `${baseUrl}multiple${filterIds}`,
        method: "DELETE",
    })
}

/**
 * 导出信息
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
// export function exportExcel(keyword) {
//     return new request({
//         url: `${baseUrl}export`,
//         method: "GET",
//         params:{...keyword,...keyword},
//         responseType: 'blob'
//     })
// }

/**
 * 导出信息
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
export function exportExcel(ids,keyword) {
    let filterIds = "?";
    ids.forEach(item => filterIds += `ids=${item}&`);
    filterIds = filterIds.substr(0, filterIds.length - 1);
    return new request({
        url: `${baseUrl}export${filterIds}`,
        method: "GET",
        params:{...keyword,...ids},
        responseType: 'blob'
    })
}



/**
 * 学生性别比例统计
 * @returns {AxiosInstance}
 */
export function chartGender() {
    return new request({
        url: `${baseUrl}chart/gender`,
        method: "GET"
    })
}

/**
 * 学生招生情况统计
 * @returns {AxiosInstance}
 */
export function chartEnrollmentPlan() {
    return new request({
        url: `${baseUrl}chart/enrollment`,
        method: "GET"
    })
}
